package com.yanqu.road.dao.impl.activity.ghost;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.ghost.config.GhostBossConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class GhostBossConfigDaoImpl extends TempDao {

    public static String getGhostBossConfigListSql = "select * from t_s_activity_ghost_boss where activityId = ?";

    public List<GhostBossConfig> getGhostBossConfigList(int activityId) {
        List<GhostBossConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getGhostBossConfigListSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                GhostBossConfig ghostBossConfig = new GhostBossConfig();
                ghostBossConfig.setActivityId(rs.getInt("activityId"));
                ghostBossConfig.setBossType(rs.getInt("bossType"));
                ghostBossConfig.setHp(rs.getInt("hp"));
                ghostBossConfig.setRewardsKill(rs.getInt("rewardsKill"));
                ghostBossConfig.setHpPer(rs.getInt("hpPer"));
                ghostBossConfig.setRewards(rs.getString("rewards"));
                ghostBossConfig.setWeight(rs.getInt("weight"));
                ghostBossConfig.setNotice(rs.getBoolean("isNotice"));
                ghostBossConfig.setBigBoss(rs.getBoolean("isBigBoss"));
                ghostBossConfig.setNpcId(rs.getInt("npcId"));
                ghostBossConfig.setRandomReward(rs.getString("randomReward"));
                list.add(ghostBossConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
